﻿using System;
using System.Collections.Generic;
using System.Text;

namespace QntPlatform
{


    public class Rootobject
    {
        public Trade Trade { get; set; }
        public Ticker Ticker { get; set; }
        public Record Record { get; set; }
        public Order Order { get; set; }
        public Marketorder MarketOrder { get; set; }
        public Depth Depth { get; set; }
        public Account Account { get; set; }
        public Position Position { get; set; }
    }

    public class Trade
    {
        public long Time { get; set; }
        public int Price { get; set; }
        public int Amount { get; set; }
        public int Type { get; set; }
    }

    public class Ticker
    {
        public object Info { get; set; }
        public decimal High { get; set; }
        public decimal Low { get; set; }
        public decimal Sell { get; set; }
        public decimal Buy { get; set; }
        public decimal Last { get; set; }
        public decimal Volume { get; set; }
        public long Time { get; set; }
    }


    public class Record
    {
        public long Time { get; set; }
        public decimal Open { get; set; }
        public decimal High { get; set; }
        public decimal Low { get; set; }
        public decimal Close { get; set; }
        public decimal Volume { get; set; }
    }

    public class Order
    {
        public object Info { get; set; }
        public int Id { get; set; }
        public int Price { get; set; }
        public int Amount { get; set; }
        public int DealAmount { get; set; }
        public int AvgPrice { get; set; }
        public int Status { get; set; }
        public int Type { get; set; }
        public int Offset { get; set; }
        public string ContractType { get; set; }
    }


    public class Marketorder
    {
        public int Price { get; set; }
        public int Amount { get; set; }
    }

    public class Depth
    {
        public object[] Asks { get; set; }
        public object[] Bids { get; set; }
        public long Time { get; set; }
    }

    /** <summary>
     Info            : {...},     // 请求交易所接口后，交易所接口应答的原始数据，回测时无此属性
    Balance         : 1000,      // 余额(人民币或者美元,在Poloniex交易所里ETC_BTC这样的品种,Balance就指的是BTC的数量,Stocks指的是ETC数量)
    FrozenBalance   : 0,         // 冻结的余额
    Stocks          : 1,         // BTC/LTC数量,数字货币现货为当前可操作币的余额(去掉冻结的币),数字货币期货的话为合约当前可用保证金(传统期货无此属性)
    FrozenStocks    : 0          // 冻结的BTC/LTC数量(传统期货无此属性)
      </summary>
      */
    public class Account
    {
        public object Info { get; set; }
        public decimal Balance { get; set; }
        public decimal FrozenBalance { get; set; }
        public decimal Stocks { get; set; }
        public decimal FrozenStocks { get; set; }
    }

    /** <summary>
     期货仓位信息,
     Info            : {...},     // 请求交易所接口后，交易所接口应答的原始数据，回测时无此属性
    MarginLevel     : 10,        // 杆杠大小
    Amount          : 100,       // 持仓量，OKEX合约交易所，表示合约的份数(整数且大于1，即合约张数)
    FrozenAmount    : 0,         // 仓位冻结量
    Price           : 10000,     // 持仓均价
    Profit          : 0,         // 持仓浮动盈亏(数据货币单位：BTC/LTC,传统期货单位:RMB,股票不支持此字段,注:OKEX合约全仓情况下指实现盈余,并非持仓盈亏,逐仓下指持仓盈亏)
    Type            : 0,         // PD_LONG为多头仓位(CTP中用closebuy_today平仓),PD_SHORT为空头仓位(CTP用closesell_today)平仓,(CTP期货中)PD_LONG_YD为咋日多头仓位(用closebuy平),PD_SHORT_YD为咋日空头仓位(用closesell平)
    ContractType    : "quarter", // 商品期货为合约代码,股票为'交易所代码_股票代码',具体参数SetContractType的传入类型
    Margin          : 1          // 仓位占用的保证金
     </summary>
    */
    public class Position
    {
        public object Info { get; set; }
        public decimal MarginLevel { get; set; }
        public decimal Amount { get; set; }
        public decimal FrozenAmount { get; set; }
        public decimal Price { get; set; }
        public decimal Profit { get; set; }
        public SideDirection Type { get; set; }
        public string ContractType { get; set; }

        public decimal Margin { get; set; }
    }
    /// <summary>
    /// 交易方向，多、空
    /// </summary>
    public enum SideDirection
    {
        /// <summary>
        /// 买多,buy long
        /// </summary>
        Buy=0,
        /// <summary>
        /// 平多, sell long
        /// </summary>
        CloseBuy=1,
        /// <summary>
        /// 买空, sell short
        /// </summary>
        Sell=2,
        /// <summary>
        /// 平空, buy short
        /// </summary>
        CloseSell=3
    }
    public static class DirectionTo
    {
        public static SideDirection CloseFor(bool? isLong)
        {
            return isLong.Value?SideDirection.CloseBuy:SideDirection.CloseSell;
        }
          public static SideDirection InFor(bool? isLong)
        {
            return isLong.Value?SideDirection.Buy:SideDirection.Sell;
        }
        public static SideDirection ToClose(this SideDirection sideDirection)
        {
            return sideDirection == SideDirection.Buy ? SideDirection.CloseBuy : SideDirection.CloseSell;
        }
    }



}
